package cn.swing.ushare.log.webapi.controller;

import cn.swing.ushare.common.web.JsonResult;
import cn.swing.ushare.log.service.ILogService;
import cn.swing.ushare.pojo.dto.LogLimitSimpleDTO;
import cn.swing.ushare.pojo.dto.SearchLogDTO;
import cn.swing.ushare.pojo.vo.LogListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/log", produces = "application/json;charset=utf-8")
public class LogController {


    @Autowired
    private ILogService logService;


    //@GetMapping("/deleteLogById")
    //public JsonResult<Void> deleteLogById(Integer id) {
    //    int change = logService.deleteOperationLogById(id);
    //    return JsonResult.ok();
    //}


    @GetMapping("/operationalLogs")
    public List<LogListVO> operationalLogs(Integer page) {
        System.out.println("page : " + page);
        LogLimitSimpleDTO userLimitSimpleDTO = new LogLimitSimpleDTO();
        userLimitSimpleDTO.setPage((page - 1) * 10);
        System.out.println("userLimitSimpleDTO = " + userLimitSimpleDTO);
        return logService.logList(userLimitSimpleDTO);
    }

    @GetMapping("/countLog")
    public Integer count(String operationType) {
        return logService.logCount(operationType);
    }


    @GetMapping("/searchLogList")
    public List<LogListVO> searchLogList(String operationType, Integer page) {
        System.out.println();
        SearchLogDTO searchLogDTO = new SearchLogDTO();
        searchLogDTO.setPage((page - 1) * 10);
        searchLogDTO.setOperationType(operationType);
        return logService.searchLogList(searchLogDTO);
    }

}
